
clear

local numG = 50
local numB = 40
local totalLength = `numG' + `numB'

local numGplus = `numG' + 1
local obs = `numGplus'^2
set obs `obs'

gen numG = floor(_n / `numGplus')
gen numB = mod(_n, `numGplus')

replace numG = 0 if _n == _N
replace numB = 0 if _n == _N

gen k = numG
gen nn = numG + numB
				
gen loglik			 = 	lnfactorial(`numB'-k) 		///
					  - lnfactorial(`numG'-k) 		///
				      + lnfactorial(`numG'-(nn-k)) 	///
					  - lnfactorial(`numB'-(nn-k))

foreach prior in 0.2 0.5 0.8 {				  
	preserve
		local prior100 = round(100*`prior')					  
							  
		gen logitPrior 		 = log(`prior' / (1 - `prior'))			  
			
		gen logitPost 		 = logitPrior + loglik	
			
							  
							  
							  
		gen bayesPost = exp(logitPost) / (1 + exp(logitPost))

		drop if numG > 40 & numB > 40

		replace bayesPost = 0 	if numB > 40
		replace bayesPost = 1 	if numG > 40



		keep numG numB bayesPost
		replace bayesPost = round(100*bayesPost)


		save "data/bayesPost`prior100'.dta", replace

	restore
}









